package com.jjlin.chapter_2;

import java.util.*;
public class CD159{
    public static class Node{
        public int val;
        public Node next;
        public Node(int data){
            this.val = data;
        }
    }

    public static Node createNodeList(int[] nums){
        if(nums == null || nums.length < 1)
            return null;
        Node head = new Node(nums[0]);
        Node pre = head;
        for(int i = 1; i < nums.length; i++){
            Node cur = new Node(nums[i]);
            pre.next = cur;
            pre = cur;
        }
        return head;
    }

    public static void printNodeList(Node head){
        Node cur = head;
        while(cur != null){
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
    }

    //合并两个有序的链表
    public static Node merge(Node head1, Node head2){
        if(head1 == null || head2 == null)
            return head1 == null ? head2 : head1;
        Node newhead = head1.val < head2.val ? head1 : head2;
        head1 = newhead == head1 ? head1.next : head1;
        head2 = newhead == head2 ? head2.next : head2;
        Node pre = newhead;
        while(head1 != null && head2 != null){
            if(head1.val < head2.val){
                pre.next = head1;
                head1 = head1.next;
            }else{
                pre.next = head2;
                head2 = head2.next;
            }
            pre = pre.next;
        }
        pre.next = head1 != null ? head1 : head2;
        return newhead;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums1 = new int[n];
        for(int i = 0; i < n; i++)
            nums1[i] = sc.nextInt();
        int m = sc.nextInt();
        int[] nums2 = new int[m];
        for(int i = 0; i < m; i++)
            nums2[i] = sc.nextInt();
        Node head1 = createNodeList(nums1);
        Node head2 = createNodeList(nums2);
        Node newhead = merge(head1, head2);
        printNodeList(newhead);
    }
}


